﻿package classes
{
	import flash.display.*;
	import flash.events.*;
	public class Mario extends MovieClip
	{

		public var left:Boolean = false;
		public var right:Boolean = false;
		public var jump:Boolean = false;
		public var mSpeed:Number = 5;
		public var mJSpeed:Number = .8;
		public var dx:Number = 0.0;
		public var dy:Number = 0.0;
		public var inAir:Boolean = true;
		public var mDirection:Number;
		public var feet:Number;
		public var lastCor:Number;

		public function Mario()
		{
			this.addEventListener(Event.ADDED_TO_STAGE, init);
			this.addEventListener(Event.ENTER_FRAME, moveMario);
		}
		public function init(e:Event){
			
			stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP, checkKeyUp);
		}
		public function moveMario(e:Event){
			if(left == true){
				this.x -= mSpeed;
			}else if(right == true){
				this.x += mSpeed;
			}else if(jump == true){
				if(inAir == false){
					var maxJump:Number = 550;
					for(var i:int = 0; i < maxJump; i++)
					{
						this.y -= .2;
					}
					inAir = true;
					jump = false;
				}
			}
			  if(inAir == true){
				  lastCor = this.y;
				  this.y += 2;
			  }else if(inAir == false){
				  this.y = this.y;
				  
			  }
		}
		public function checkKeyDown(e:KeyboardEvent){
			if(e.keyCode == 37){
				this.left = true;
			}else if(e.keyCode == 39){
				this.right = true;
			}else if(e.keyCode == 38){
				this.jump = true;
			}

		}
		public function checkKeyUp(e:KeyboardEvent){
			if(e.keyCode == 37){
				this.left = false;
			}else if(e.keyCode == 39){
				this.right = false;
			}

		}
	}
}